package org.sixtythousand.joker.netty;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.FullHttpRequest;
import org.sixtythousand.joker.JChannel;
import org.sixtythousand.joker.Request;
import org.sixtythousand.joker.handler.Handler;
import org.sixtythousand.joker.http.HttpChannel;
import org.sixtythousand.joker.http.HttpConnection;
import org.sixtythousand.joker.http.HttpRequest;
import org.sixtythousand.joker.http.HttpResponse;
import org.sixtythousand.joker.servlet.SimpleResponse;

import java.util.concurrent.Executor;

/**
 * @author zhoulk
 * @date 2023/10/11 15:34
 * @desc
 */
public class NettyConnection extends HttpConnection {


    protected ChannelHandlerContext channelHandlerContext;


    protected NettyConnection(HttpChannel channel, Handler handler, Executor executor) {
        super(channel, handler);
        this.executor = executor;
    }

    @Override
    public void doRead(Object msg) {
        if (msg instanceof Request) {
            Request request = (Request) msg;
//            if (request.isStarted()) {
                handler.handle(newHttpRequest(request), newHttpResponse(request));
//            }
        }
    }

    @Override
    public JChannel getChannel() {
        return null;
    }

    @Override
    public Executor getExecutor() {
        return null;
    }

    @Override
    public HttpRequest newHttpRequest(Request request) {
        if (request instanceof NettyHttpRequest) {
            return (NettyHttpRequest) request;
        } else {
            // todo
            return null;
        }
    }

    @Override
    public HttpResponse newHttpResponse(Request request) {
        if (request instanceof NettyHttpRequest) {
            return new NettyHttpResponse((NettyHttpRequest) request);
        } else {
            // todo
            return null;
        }
    }


}
